package cs551.listtracker.structure;

import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;

import android.os.Parcel;
import android.os.Parcelable;

@Root(name="Lists")
public class ListContainer implements Parcelable {
	public static final Parcelable.Creator<ListContainer> CREATOR = new Parcelable.Creator<ListContainer>() {
		public ListContainer createFromParcel(Parcel source) {
			return new ListContainer(source);
		}

		@Override
		public ListContainer[] newArray(int size) {
			return new ListContainer[size];
		}
	};

	@ElementList(type=ShoppingList.class,name="List")
	public List<ShoppingList> lists = new ArrayList<ShoppingList>();

	public ListContainer() {

	}

	public ListContainer(Parcel source) {

		source.readList(lists, ListContainer.class.getClassLoader());

	}

	public void exportListToWriter(FileOutputStream fos) throws Exception {

		Serializer serializer = new Persister();
		serializer.write(this, fos);
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel out, int flags) {
		out.writeList(lists);
	}
}
